package cn.antblog.jvm.threadPool;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @ClassName TestScheduled
 * @Description 定时器
 * @Author YangJingyi
 * @Date 2023/8/3 14:52
 * @Version 1.0
 */
public class TestScheduled {

//    public static void main(String[] args) throws ExecutionException, InterruptedException {
//        //直接设定核心线程数为1
//        ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1);
//        //这里我们计划在3秒后执行
//        executor.schedule(() -> System.out.println("HelloWorld!"), 3, TimeUnit.SECONDS);
//
//        executor.shutdown();
//    }

//    public static void main(String[] args) throws ExecutionException, InterruptedException {
//        ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(2);
//        //这里使用ScheduledFuture
//        ScheduledFuture<String> future = executor.schedule(() -> "????", 3, TimeUnit.SECONDS);
//        System.out.println("任务剩余等待时间："+future.getDelay(TimeUnit.MILLISECONDS) / 1000.0 + "s");
//        System.out.println("任务执行结果："+future.get());
//        executor.shutdown();
//    }


    /** 固定频率 */
//    public static void main(String[] args) throws ExecutionException, InterruptedException {
////        ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(2);
////        executor.scheduleAtFixedRate(() -> System.out.println("Hello World!"),
////                3, 1, TimeUnit.SECONDS);
////        //三秒钟延迟开始，之后每隔一秒钟执行一次
//
//    }
    public static void main(String[] args) {
//        final int COUNT_BITS = Integer.SIZE - 3;    //29位，线程数量位
//        final int RUNNING = -1 << COUNT_BITS;
//        System.out.println(RUNNING);
//        String binaryNumber = Integer.toBinaryString(RUNNING);
//        System.out.println(binaryNumber); // 输出二进制数
//        String fuyi = Integer.toBinaryString(3);
//        System.out.println(fuyi); // 输出二进制数
        final int _INITED = 1;
        String _INITED2 = Integer.toBinaryString(_INITED);
        System.out.println(_INITED2);
        final int _CREATED = 2 | _INITED;
        String _CREATED2 = Integer.toBinaryString(_CREATED);
        System.out.println(_CREATED2);
        final int _PREPARED = 4 | _CREATED;
        final int _RUNNING = 8 | _PREPARED;
        final int _FINISHED = 16 | _PREPARED;
        final int _FAILED = 32 | _FINISHED;
        final int _STOPPED = 64 | _FINISHED;
        final int _SKIPPED = 128 | _FINISHED;

    }



}
